<template>
    <fieldset>
        <legend>列表页</legend>
        <ul v-if="goods.length">
            <li v-for="item in goods" :key="item.id">
                <!-- <router-link :to="`/detail/${item.productId}`">{{item.productName}}</router-link> -->
                <a href="javascript:" @click="jump(item.productId)">{{item.productName}}</a>
            </li>
        </ul>
        <h2 v-else>正在加载....</h2>
    </fieldset>
</template>

<script>
//列表页接口
//http://chst.vip:1234/api/getmoneyctrl
export default{
    data(){
        return{
            goods:[]
        }
    },
    mounted(){
        // 发起请求
        fetch('http://chst.vip:1234/api/getmoneyctrl')
        .then(body=>body.json())
        .then(res=>{
            // console.log(res);
            let{result:data}=res;//{result:data}解构res中的resul并起别名data
            this.goods=data;
            console.log(goods);
        })
    },
    methods:{
        jump(id){
            this.$router.push(`detail/${id}`)
        }
        
    }
    
}
</script>
